package com.simpleim.starter.command;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import java.util.Scanner;

/**
 * 登录命令
 */
@Service
public class LoginCommand implements BaseCommand{

    private static final Logger LOG = LoggerFactory.getLogger(LoginCommand.class);

    private String username;

    private String password;

    public static final String KEY = "1";

    @Override
    public void exec(Scanner scanner) {
        System.err.println("请用(user@password的格式输入账号：)");
        while (true) {
            String inputCon = scanner.next();
            String[] strs = inputCon.split("@");
            if (strs.length != 2) {
                System.err.println("格式不正确，请重新输入");
                continue;
            }

            username = strs[0];
            password = strs[1];

            // 发送数据到服务端
            return;
        }
    }

    @Override
    public String title() {
        return "登录";
    }

    @Override
    public String type() {
        return KEY;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }
}
